home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-brush.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  4.4 KB  |  144 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Selection-to-brush
  5. ; Copyright (c) 1997 Adrian Likins
  6. ; aklikins@eos.ncsu.edu
  7. ;
  8. ; Takes the current selection, saves it as a brush, and makes it the
  9. ; active brush..
  10. ;
  11. ;       Parts of this script from Sven Neuman's Drop-Shadow and
  12. ;       Seth Burgess's mkbrush scripts.
  13. ;
  14. ; This program is free software: you can redistribute it and/or modify
  15. ; it under the terms of the GNU General Public License as published by
  16. ; the Free Software Foundation; either version 3 of the License, or
  17. ; (at your option) any later version.
  18. ;
  19. ; This program is distributed in the hope that it will be useful,
  20. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ; GNU General Public License for more details.
  23. ;
  24. ; You should have received a copy of the GNU General Public License
  25. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  26.  
  27.  
  28. (define (script-fu-selection-to-brush image
  29.                                       drawable
  30.                                       name
  31.                                       filename
  32.                                       spacing)
  33.   (let* (
  34.         (type (car (gimp-drawable-type-with-alpha drawable)))
  35.         (selection-bounds (gimp-selection-bounds image))
  36.         (select-offset-x  (cadr selection-bounds))
  37.         (select-offset-y  (caddr selection-bounds))
  38.         (selection-width  (- (cadr (cddr selection-bounds))  select-offset-x))
  39.         (selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  40.         (from-selection 0)
  41.         (active-selection 0)
  42.         (brush-draw-type 0)
  43.         (brush-image-type 0)
  44.         (brush-image 0)
  45.         (brush-draw 0)
  46.         (filename2 0)
  47.         )
  48.  
  49.     (gimp-context-push)
  50.  
  51.     (gimp-image-undo-disable image)
  52.  
  53.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  54.         (begin
  55.           (gimp-selection-layer-alpha drawable)
  56.           (set! from-selection FALSE)
  57.         )
  58.         (begin
  59.           (set! from-selection TRUE)
  60.           (set! active-selection (car (gimp-selection-save image)))
  61.         )
  62.     )
  63.  
  64.     (gimp-edit-copy drawable)
  65.  
  66.     (set! brush-draw-type
  67.           (if (= type GRAYA-IMAGE)
  68.               GRAY-IMAGE
  69.               RGBA-IMAGE))
  70.  
  71.     (set! brush-image-type
  72.           (if (= type GRAYA-IMAGE)
  73.               GRAY
  74.               RGB))
  75.  
  76.     (set! brush-image (car (gimp-image-new selection-width
  77.                                            selection-height
  78.                                            brush-image-type)))
  79.  
  80.     (set! brush-draw
  81.           (car (gimp-layer-new brush-image
  82.                                selection-width
  83.                                selection-height
  84.                                brush-draw-type
  85.                                "Brush"
  86.                                100
  87.                                NORMAL-MODE)))
  88.  
  89.     (gimp-image-add-layer brush-image brush-draw 0)
  90.  
  91.     (gimp-selection-none brush-image)
  92.  
  93.     (if (= type GRAYA-IMAGE)
  94.         (begin
  95.           (gimp-context-set-background '(255 255 255))
  96.           (gimp-drawable-fill brush-draw BACKGROUND-FILL))
  97.         (gimp-drawable-fill brush-draw TRANSPARENT-FILL)
  98.     )
  99.  
  100.     (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE))))
  101.       (gimp-floating-sel-anchor floating-sel)
  102.     )
  103.  
  104.     (set! filename2 (string-append gimp-directory
  105.                                    "/brushes/"
  106.                                    filename
  107.                                    (number->string image)
  108.                                    ".gbr"))
  109.  
  110.     (file-gbr-save 1 brush-image brush-draw filename2 "" spacing name)
  111.  
  112.     (if (= from-selection TRUE)
  113.         (begin
  114.           (gimp-selection-load active-selection)
  115.           (gimp-image-remove-channel image active-selection)
  116.         )
  117.     )
  118.  
  119.     (gimp-image-undo-enable image)
  120.     (gimp-image-set-active-layer image drawable)
  121.     (gimp-image-delete brush-image)
  122.     (gimp-displays-flush)
  123.  
  124.     (gimp-context-pop)
  125.  
  126.     (gimp-brushes-refresh)
  127.     (gimp-context-set-brush name)
  128.   )
  129. )
  130.  
  131. (script-fu-register "script-fu-selection-to-brush"
  132.   _"To _Brush..."
  133.   _"Convert a selection to a brush"
  134.   "Adrian Likins <adrian@gimp.org>"
  135.   "Adrian Likins"
  136.   "10/07/97"
  137.   "RGB* GRAY*"
  138.   SF-IMAGE       "Image"       0
  139.   SF-DRAWABLE    "Drawable"    0
  140.   SF-STRING     _"Brush name"  "My Brush"
  141.   SF-STRING     _"File name"   "mybrush"
  142.   SF-ADJUSTMENT _"Spacing"     '(25 0 1000 1 1 1 0)
  143. )
  144.